package com.like.miaosha.controller;

import com.like.miaosha.domain.MiaoshaUser;
import com.like.miaosha.domain.OrderInfo;
import com.like.miaosha.result.CodeMsg;
import com.like.miaosha.result.Result;
import com.like.miaosha.service.GoodsService;
import com.like.miaosha.service.OrderService;
import com.like.miaosha.vo.GoodsVo;
import com.like.miaosha.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName orderController
 * @Description: TODO
 * @Author dongfengke
 * @Date 2022/1/16
 * @Version V1.0
 **/
public class orderController {

    @Autowired
    GoodsService goodsService;
    @Autowired
    OrderService orderService;

    @RequestMapping("/detail")
    @ResponseBody
    public Result<OrderDetailVo> info(Model model, MiaoshaUser user, @RequestParam("orderId") long orderId){
        if(user==null) return Result.error(CodeMsg.SESSION_ERROR);
        OrderInfo order=orderService.getOrderById(orderId);
        if(order==null) return Result.error(CodeMsg.ORDER_NOT_EXIST);
        long goodsId=order.getGoodsId();
        GoodsVo goods = goodsService.getGoodsVoByGoodsId(goodsId);
        OrderDetailVo vo=new OrderDetailVo();
        vo.setOrder(order);
        vo.setGoods(goods);
        return Result.success(vo);
    }

}
